/***********************************************************************
 * Module Pattern (How to write classes with private and public members)
 ***********************************************************************/

print("blah");
var module = (function () {
   // private vars and funcs
    var foo = "bar";
    var five = 5;
    var myName = "";

    // constructor
    var module = function(name){
        print("module is being constructed");
        print("the module's name is " + name);
        myName = name;
    };

    // prototype
    module.prototype = {
        x : 0,  // public variable

        constructor: module,

        addX: function(){
            this.x = this.x + 3;
            print(five);
        },

        subX: function(){
            this.x = this.x - 2;
            print("my name is " + myName);
        }
    };

    // return the module
    return module;
})();

print("before module");
var myModule = new module("brian");
print("after module construction");

print(myModule.x);
myModule.addX();
print(myModule.x);
myModule.subX();
print(myModule.x);

